package com.example.schoolmgt.dao;

import com.example.schoolmgt.model.School;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface SchoolDao {

    //用户列表
    @Select("select * from school")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name")
    })
    List<School> queryAll();

    //根据id获取school
    @Select("select * from school where id =#{id}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name")
    })
    School findSchoolById(Long id);

    //根据id修改school
    @Update("update school set name=#{name} WHERE id = #{id} ")
    int updateSchool(School school);

    //根据id删除用户
    @Delete("delete from school where id = #{id}")
    int deleteSchoolById(Long id);

    @Insert("insert into school (name) values(#{name})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void saveSchool(School school);
}
